import request from '@/utils/request'
// 获取图片列表
export function getImageList() {
    return request({
        url: '/t-system-svg-file/getAll',
        method: 'get'
    })
}
// 获取区域设备列表
export function getDrawList(data) {
    return request({
        url: '/mt-system/organization/listOrgDeviceTree',
        method: 'get',
        params: data
    })
}

// 获取区域列表
export function regionList(data) {
    return request({
        url: '/mt-system/organization/listAll',
        method: 'get',
        params: data
    })
}



// 获取传感器列表
export const getHostSensor = (data) => {
    return request({
        url: '/mt-system/device/getDeviceSensor',
        method: 'get',
        params: data
    })
}

// 获取传感器数据
export const getSensorData = (data) => {
    return request({
        url: '/mt-system/device/getDeviceSensorData',
        method: 'get',
        params: data
    })
}

// 获取区域类型列表
export const getRegionTypeList = (data) => {
    return request({
        url: '/mt-system/organization/getOrgnationDataType',
        method: 'get',
        params: data
    })
}

// /mt-system/organization/getOrgnationData
export const getRegionData = (data) => {
    return request({
        url: '/mt-system/organization/getOrgnationData',
        method: 'get',
        params: data
    })
}

// 
export const getDrawListByOrgId = (data) => {
    return request({
        url: '/mt-system/t-system-draw/selectTSystemDrawByOrgId',
        method: 'get',
        params: data
    })
}

// /mt-system/t-system-draw/add
export const addDraw = (data) => {
    return request({
        url: '/mt-system/t-system-draw/add',
        method: 'post',
        data
    })
}




// 转换树形
export function toTree(data) {
    let result = []
    if (!Array.isArray(data)) {
        return result
    }
    let map = {}
    data.forEach(item => {
        map[item.id] = item
    })
    data.forEach(item => {
        let parent = map[item.pid]
        if (parent) {
            (parent.children || (parent.children = [])).push(item)
        } else {
            result.push(item)
        }
    })
    return result
}


